/*********************************************************************************/
/*                                                                               */
/*      SPI Driver                                                               */
/*                                                                               */
/*      Last updated by:   CBS                                                   */
/*      Last update date:  13/01/15                                              */
/*      Revision:          0                                                     */
/*      Copyright:         DENSO                                                 */
/*                                                                               */
/*********************************************************************************/
#ifndef SPI_H_
#define SPI_H_

/*********************************************************************************/
/*  include files                                                                */
/*********************************************************************************/
#include "Std_Types.h"
#include "Spi_Cfg.h"

/*********************************************************************************/
/*  defines / data types / structs / unions / macros                             */
/*********************************************************************************/
#define SPI_VENDOR_ID                1
#define SPI_MODULE_ID                83
#define SPI_INSTANCE_ID              0

/* Version Information */
#define SPI_SW_MAJOR_VERSION         1
#define SPI_SW_MINOR_VERSION         0
#define SPI_SW_PATCH_VERSION         0
#define SPI_AR_MAJOR_VERSION         0
#define SPI_AR_MINOR_VERSION         0
#define SPI_AR_PATCH_VERSION         0

#define MODULE_NAME  "/driver/Spi"

#define ARRAY_SIZE(_x) (sizeof(_x) / sizeof((_x)[0]))

#define GET_SPI_HW_PTR(_unit) ((struct DSPI_tag *)(0xFFF90000 + 0x4000*(_unit)))

#define GET_SPI_UNIT_PTR(_unit)  &Spi_Unit[(_unit)]

#define VALIDATE(_exp,_api,_err )
#define VALIDATE_W_RV(_exp,_api,_err,_rv )

#define NOT_VALID  (-1)

typedef union
{
    U4 R;
    
    struct {
    U4 CONT:1;
    U4 CTAS:3;
    U4 EOQ:1;
    U4 CTCNT:1;
    U4:4;
    U4 PCS5:1;
    U4 PCS4:1;
    U4 PCS3:1;
    U4 PCS2:1;
    U4 PCS1:1;
    U4 PCS0:1;
    U4 TXDATA:16;
    } B;
}SPICommandType;

typedef SPICommandType Spi_CommandType;

typedef enum{
    SPI_UNINIT = 0,
    SPI_IDLE,
    SPI_BUSY
} Spi_StatusType;

typedef enum{
    SPI_JOB_OK = 0,
    SPI_JOB_PENDING,
    SPI_JOB_FAILED
} Spi_JobResultType;

typedef enum{
    SPI_SEQ_OK,
    SPI_SEQ_PENDING,
    SPI_SEQ_FAILED,
    SPI_SEQ_CANCELLED
} Spi_SeqResultType;


/*********************************************************************************/
/*  API Functions                                                                */
/*********************************************************************************/
void Spi_SetSlave(U4 unit);
void Spi_JobWrite( Spi_JobType jobIndex );
void Spi_Init (const Spi_ConfigType* ConfigPtr);

Std_ReturnType Spi_DeInit (void);

Std_ReturnType Spi_WriteIB (Spi_ChannelType Channel, const Spi_DataType* DataBufferPtr);

Std_ReturnType Spi_ReadIB (Spi_ChannelType Channel,  Spi_DataType* DataBufferPointer);

Std_ReturnType Spi_SetupEB (Spi_ChannelType Channel, const Spi_DataType* SrcDataBufferPtr,
    Spi_DataType* DesDataBufferPtr, Spi_NumberOfDataType Length);

Spi_StatusType Spi_GetStatus( void );
Spi_JobResultType Spi_GetJobResult ( Spi_JobType Job );
Spi_SeqResultType Spi_GetSequenceResult(Spi_SequenceType Sequence );


Std_ReturnType Spi_SyncTransmit (Spi_SequenceType Sequence);

#if ( SPI_VERSION_INFO_API == STD_ON )
void Spi_GetVersionInfo (Std_VersionInfoType* versioninfo);
#endif

#endif
